package com.gopay.cron.service.cloud.gen.bean;

import com.gopay.cron.web.vo.CloudAccountStatementVO;

/**
 * Created by Johnson on 2017/3/1.
 */
public class TransferFileInfo {

    public static final String fileName = "03";
    public static final String fileFtpName = "云账户转账类";

    public static final String txtFirstLine = "商户订单号\t国付宝账户号\t转账类型\t转入方协议号\t转账金额\t手续费\t转账请求时间\t清算时间";
    public static final String csvFirstLine = "\"商户订单号\",\"国付宝账户号\",\"转账类型\",\"转入方协议号\",\"转账金额\",\"手续费\",\"转账请求时间\",\"清算时间\"";

    private static final String csvFtpFirstLine = "\"商户账户\",\"转账总笔数\",\"转账总金额\",\"转账总手续费\"";
    private static final String csvFtpSecondLine = "\"国付宝交易号\",\"商户订单号\",\"交易类型\",\"发起时间\",\"完成时间\",\"转入方协议号\",\"转账金额\",\"手续费\",\"手续费承担方\"";

    private StringBuilder txtLineContent = new StringBuilder();
    private StringBuilder csvLineContent = new StringBuilder();
    private StringBuilder csvFtpFirstLineContent = new StringBuilder();
    private StringBuilder csvFtpSecondLineContent = new StringBuilder();

    public void addTransferFileLine(CloudAccountStatementVO vo) {
        addTxtFileLine(vo);
        addCsvFileLine(vo);
    }


    public void addTxtFileLine(CloudAccountStatementVO vo) {
        txtLineContent.append(vo.getMerOrderId()).append("\t")
                .append(vo.getGopayAcct()).append("\t")
                .append(vo.getGopayIntTxnCd()).append("\t")
                .append(vo.getRecvAcctId()).append("\t")
                .append(vo.getMerTxnAmt()).append("\t")
                .append(vo.getOrderFeeAmt()).append("\t")
                .append(vo.getReqTime()).append("\t")
                .append(vo.getTranFinishTime())
                .append("\r\n");
    }

    public void addCsvFileLine(CloudAccountStatementVO vo) {
        csvLineContent.append("\"").append(vo.getMerOrderId()).append("\",")
                .append("\"").append(vo.getGopayAcct()).append("\",")
                .append("\"").append(vo.getGopayIntTxnCd()).append("\",")
                .append("\"").append(vo.getRecvAcctId()).append("\",")
                .append("\"").append(vo.getMerTxnAmt()).append("\",")
                .append("\"").append(vo.getOrderFeeAmt()).append("\",")
                .append("\"").append(vo.getReqTime()).append("\",")
                .append("\"").append(vo.getTranFinishTime()).append("\"")
                .append("\r\n");
    }

    public String getTxtContent() {
        StringBuilder sb = new StringBuilder(TransferFileInfo.txtFirstLine);
        sb.append("\r\n").append(txtLineContent.toString());
        return sb.toString();
    }

    public String getFtpCsvContent() {
        StringBuilder sb = new StringBuilder(TransferFileInfo.csvFtpFirstLine);
        sb.append("\r\n").append(csvFtpFirstLineContent.toString());
        sb.append(TransferFileInfo.csvFtpSecondLine);
        sb.append("\r\n").append(csvFtpSecondLineContent.toString());
        return sb.toString();
    }

    public String getCsvContent() {
        StringBuilder sb = new StringBuilder(TransferFileInfo.csvFirstLine);
        sb.append("\r\n").append(csvLineContent.toString());
        return sb.toString();
    }

    public void addFtpFirstTransferFileLine(CloudAccountStatementVO vo) {
        addFtpFirstCsvFileLine(vo);
    }

    private void addFtpFirstCsvFileLine(CloudAccountStatementVO vo) {
        csvFtpFirstLineContent.append("\"").append(vo.getGopayAcct()).append("\",")
                .append("\"").append(vo.getTotalCount()).append("\",")
                .append("\"").append(vo.getTotalTxnAmt()).append("\",")
                .append("\"").append(vo.getTotalFeeAmt()).append("\"")
                .append("\r\n");
    }

    public void addFtpSecondTransferFileLine(CloudAccountStatementVO vo) {
        addFtpSecondCsvFileLine(vo);
    }

    private void addFtpSecondCsvFileLine(CloudAccountStatementVO vo) {
        csvFtpSecondLineContent.append("\"").append(vo.getGopayOrderId()).append("\",")
                .append("\"").append(vo.getMerOrderId()).append("\",")
                .append("\"").append(vo.getGopayIntTxnCd()).append("\",")
                .append("\"").append(vo.getReqTime()).append("\",")
                .append("\"").append(vo.getTranFinishTime()).append("\",")
                .append("\"").append(vo.getAgreeId()).append("\",")
                .append("\"").append(vo.getMerTxnAmt()).append("\",")
                .append("\"").append(vo.getOrderFeeAmt()).append("\",")
                .append("\"").append(vo.getOrderFeePayer()).append("\"")
                .append("\r\n");
    }
}
